package com.kmxd.ams.app.event.efile;

import com.kmxd.ams.app.event.efile.command.AttachmentConvertCmd;
import com.kmxd.ams.app.event.efile.command.DocFileNumCmd;
import com.kmxd.ams.app.event.efile.command.EfileConvertCmd;
import com.kmxd.ams.client.event.efile.AttachmentConvertEvent;
import com.kmxd.ams.client.event.efile.DocFileNumEvent;
import com.kmxd.ams.client.event.efile.EfileConvertEvent;
import com.kmxd.ams.client.event.efile.EfileOcrEvent;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.transaction.event.TransactionalEventListener;

/**
 * 电子文件 监听
 *
 * @author ZuoLG
 */
@Slf4j
@Component
@AllArgsConstructor
public class EfileListener {

  private final DocFileNumCmd docFileNumCmd;
  private final EfileConvertCmd efileConvertCmd;
  private final AttachmentConvertCmd attachmentConvertCmd;

  /**
   * 电子文件转换
   *
   * @param event
   * @throws Exception
   */
  @TransactionalEventListener(fallbackExecution = true)
  public void efileConvert(EfileConvertEvent event) throws Exception {
    efileConvertCmd.efileConvert(event);
  }

  /**
   * 修改电子文件数量
   *
   * @param event
   * @throws Exception
   */
  @TransactionalEventListener(fallbackExecution = true)
  public void editFileNum(DocFileNumEvent event) throws Exception {
    docFileNumCmd.editFileNum(event);
  }

  @TransactionalEventListener(fallbackExecution = true)
  public void ocr(EfileOcrEvent event) throws Exception {
  }

  @TransactionalEventListener(fallbackExecution = true)
  public void attachmentConvert(AttachmentConvertEvent event) throws Exception {
    attachmentConvertCmd.efileConvert(event);
  }
}
